package main

import (
	"fmt"
	_ "math"
)

func main() {
	var age int = 100

	if age < 0 {
		fmt.Println("输入有误")
	} else if age > 20 && age > 0 {
		fmt.Println("青少年")
	} else {
		fmt.Println("不是青少年")
	}

	var year int32 = 2001
	if year%400 == 0 || (year%4 == 0 && year%400 != 0) {
		fmt.Println("闰年")
	}

	//switch
	var s int = 1
	switch test2(s) {
	case 1, 3:
		fmt.Println("a")
	case test(), s, 5:
		fmt.Println("b")
	default:
		fmt.Println("c")
	}

	//用法二
	switch {
	case s == 1:
		fmt.Println("a")
	default:
		fmt.Println("v")
	}

	//用法三
	switch age := 10; {
	case age > 10:
		fmt.Println("a")
	default:
		fmt.Println("v")
	}

	var x interface{}
	var y int = 100
	x = y
	//用法四,判断这个参数是什么数据结构的
	switch w := x.(type) {
	case nil:
		fmt.Println("nil")
		fmt.Printf("%v\n", w)
	case int:
		fmt.Println("int")
		fmt.Printf("%v\n", w)
	case func(int) float64:
		fmt.Println("func(int) float64")
	default:
		fmt.Println("error")
		fmt.Printf("%v\n", w)
	}

	fmt.Println("switch 穿透---fallthrought")
	//switch 穿透---fallthrought，默认只穿一层
	var chuan int32 = 1
	switch chuan {
	case 1:
		fmt.Println("a")
		fallthrough
	case 2:
		fmt.Println("2")
		//fallthrough
	default:
		fmt.Println("v")
	}
}

func test() int {
	return 2
}

func test2(b int) int {
	return 2 + b
}
